/*
 * Progetto IGPE
 * Ultima modifica 09/04/2014
 * Autori
 * Luccisano Girolamo
 * Francesco mangione
 */
package world.gameMenager;
import gui.gui2d.Promotion;
import gui.gui2d.highLevelPanels.utils.GuiTrigger;

import java.util.Observable;
import java.util.Observer;

import multiplayer.lan.utility.Message;

import com.sun.org.apache.bcel.internal.generic.INSTANCEOF;

import utility.EventClick;
import utility.Point;
import world.Chess;
import world.Piece;
import world.player.LocalPlayer;
import world.player.Player;
public abstract class GameManager extends Observable implements Observer{
	protected Chess 	chess;
	protected Player 	lastToPlay;
	public GameManager() {
		chess=new Chess();
	}
	public Chess getChess() {
		return chess;
	}
	public void setChess(Chess chess) {
		this.chess = chess;
	}
	public void loadPiceOnMatrix(){
		chess.reset();
	}
	public Player getLastToPlay() {
		return lastToPlay;
	}
	public void setLastToPlay(Player lastToPlay) {
		this.lastToPlay = lastToPlay;
		setChanged();
		notifyObservers(new GuiTrigger(GuiTrigger.LAST_TO_PLAY, lastToPlay));
	}
	public abstract boolean canMove(Player p);
	public abstract void move(Player currentPlayer , Point from , Point to);

	public void notifyClick(Player player, Point point) {
		if(player instanceof LocalPlayer){
			if(!getLastToPlay().equals(player)){
				setChanged();
				notifyObservers(new EventClick(player,point));
			}
		}
	}
	
	public void sendPromotion(Promotion p ){
		setChanged();
		notifyObservers(p);
	}
	
	public void youCantMove(LocalPlayer localPlayer) {
		setChanged();
		notifyObservers(new GuiTrigger(GuiTrigger.YOU_CANT_MOVE, localPlayer));
		
	}
	public void makePromotionPown(Piece piece) {
		throw new UnsupportedOperationException("Class piece can't do this operation. You must use subclass");
		
	}
	public void receivePromotionFromLan(Piece piecePromotion) {
		throw new UnsupportedOperationException("Class piece can't do this operation. You must use subclass");
		
		
	}
	public void sendMessageFromLocalPlayer(String message) {
		throw new UnsupportedOperationException("Class piece can't do this operation. You must use subclass");
		
	}
	public void receiveMessageFromRemotePlayer(Message mess) {
		throw new UnsupportedOperationException("Class piece can't do this operation. You must use subclass");

		
	}
	
	public void connectionLost(String messsage){
		throw new UnsupportedOperationException("Class piece can't do this operation. You must use subclass");

	}
}
